From 7fc701d73f1b352239e8813aa41276843f115add Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 23 Sep 2003 13:39:53 +0000 Subject: [PATCH] Add tabsep, fix potential null deref on link text csv output, doc LAT_DIR, LON_DIR. Mostly from Rick Richardson. --- gpsbabel/Makefile | 8 +++--- gpsbabel/README | 4 +++ gpsbabel/csv_util.c | 5 ++-- gpsbabel/internal_styles.c | 50 ++++++++++++++++++++++++++++++++++++- gpsbabel/style/README.style | 4 +++ gpsbabel/style/tabsep.style | 46 ++++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 gpsbabel/style/tabsep.style diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index dbf92b10c..e182b6c0f 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -66,11 +66,11 @@ leaktest: dep: make clean && make CC="gcc -MMD" && cat *.d */*.d > /tmp/dep && rm *.d */*.d - (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e "\t./mkstyle.sh > $@ || (rm -f $@ ; exit 1)" ) >> /tmp/dep + (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e '\t./mkstyle.sh > $@ || (rm -f $@ ; exit 1)' ) >> /tmp/dep echo Edit Makefile and bring in /tmp/dep -VERSIONU=1_1_1_beta09042003 -VERSIOND=1.1.1_beta09042003 +VERSIONU=1_1_1_beta09232003 +VERSIOND=1.1.1_beta09232003 release: ./chkdoc rm -fr gpsbabel-$(VERSIOND) @@ -187,4 +187,4 @@ jeeps/gpsutil.o: jeeps/gpsutil.c jeeps/gps.h jeeps/gpsport.h \ jeeps/gpsmath.h jeeps/gpsnmea.h jeeps/gpsmem.h jeeps/gpsrqst.h \ jeeps/gpsinput.h jeeps/gpsproj.h jeeps/gpsnmeafmt.h jeeps/gpsnmeaget.h internal_styles.c: mkstyle.sh style/README.style style/arc.style style/csv.style style/custom.style style/dna.style style/fugawi.style style/gpsdrive.style style/gpsman.style style/mapconverter.style style/mxf.style style/nima.style style/ozi.style style/s_and_t.style style/xmap.style style/xmapwpt.style - ./mkstyle.sh > dep || (rm -f dep ; exit 1) + ./mkstyle.sh > $@ || (rm -f $@ ; exit 1) diff --git a/gpsbabel/README b/gpsbabel/README index b0af83c6b..898f6e067 100644 --- a/gpsbabel/README +++ b/gpsbabel/README @@ -385,6 +385,10 @@ THE FORMATS to text so it can be pulled into a spreadsheet or manipulated with text processing tools. + tabsep + + Dumps all fields in a traditional Unix tab separated style. + mapconverter Mapconverter is a format this is read by Mapopolis.com's mapconverter diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index b07320932..b87470b77 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -29,6 +29,7 @@ /* macros */ #define LAT_DIR(a) a < 0.0 ? 'S' : 'N' #define LON_DIR(a) a < 0.0 ? 'W' : 'E' +#define NONULL(a) a ? a : "" /* convert excel time (days since 1900) to time_t and back again */ #define EXCEL_TO_TIMET(a) ((a - 25569.0) * 86400.0) @@ -681,10 +682,10 @@ xcsv_waypt_pr(const waypoint *wpt) strcpy(buff, "\"\""); } else if (strcmp(fmp->key, "URL_LINK_TEXT") == 0) { - sprintf(buff, fmp->printfc, wpt->url_link_text); + sprintf(buff, fmp->printfc, NONULL(wpt->url_link_text)); } else if (strcmp(fmp->key, "ICON_DESCR") == 0) { - sprintf(buff, fmp->printfc, wpt->icon_descr); + sprintf(buff, fmp->printfc, NONULL(wpt->icon_descr)); } else /* LATITUDE CONVERSION***********************************************/ diff --git a/gpsbabel/internal_styles.c b/gpsbabel/internal_styles.c index c60f91b74..29b5b11eb 100644 --- a/gpsbabel/internal_styles.c +++ b/gpsbabel/internal_styles.c @@ -456,6 +456,54 @@ static char s_and_t[] = "IFIELD URL, \"\", \"%s\" # URL\n" "IFIELD IGNORE, \"\", \"\" # Holder for Geocache Type\n" ; +static char tabsep[] = +"# gpsbabel XCSV style file\n" +"#\n" +"# Format: Dumps all fields in a traditional Unix tab separated style\n" +"#\n" +"# The order of the fields (with the exception of LAT_DIR/LON_DIR) was\n" +"# the same as documented in README.style when this format was created.\n" +"# LAT_DIR/LON_DIR were undocumented, so I stuck them at the end of the\n" +"# other lat/lon fields.\n" +"#\n" +"# However, please add any new gpsbabel fields to the end (to avoid\n" +"# upsetting existing applications) regardless of where they land in\n" +"# the README.style documentation.\n" +"#\n" + +"DESCRIPTION All database fields on one tab-separated line\n" + +"# FILE LAYOUT DEFINITIIONS:\n" +"#\n" +"FIELD_DELIMITER TAB\n" +"RECORD_DELIMITER NEWLINE\n" +"BADCHARS TAB\n" + +"#\n" +"# INDIVIDUAL DATA FIELDS:\n" +"#\n" +"IFIELD INDEX, \"\", \"%d\"\n" +"IFIELD SHORTNAME, \"\", \"%s\"\n" +"IFIELD DESCRIPTION, \"\", \"%s\"\n" +"IFIELD NOTES, \"\", \"%s\"\n" +"IFIELD URL, \"\", \"%s\" \n" +"IFIELD URL_LINK_TEXT, \"\", \"%s\"\n" +"IFIELD ICON_DESCR, \"\", \"%s\"\n" +"IFIELD LAT_DECIMAL, \"\", \"%f\"\n" +"IFIELD LON_DECIMAL, \"\", \"%f\"\n" +"IFIELD LAT_INT32DEG, \"\", \"%ld\"\n" +"IFIELD LON_INT32DEG, \"\", \"%ld\"\n" +"IFIELD LAT_DECIMALDIR, \"\", \"%f/%c\"\n" +"IFIELD LON_DECIMALDIR, \"\", \"%f/%c\"\n" +"IFIELD LAT_DIRDECIMAL, \"\", \"%c/%f\"\n" +"IFIELD LON_DIRDECIMAL, \"\", \"%c/%f\"\n" +"IFIELD LAT_DIR, \"\", \"%c\"\n" +"IFIELD LON_DIR, \"\", \"%c\"\n" +"IFIELD ALT_FEET, \"\", \"%fF\"\n" +"IFIELD ALT_METERS, \"\", \"%fM\"\n" +"IFIELD EXCEL_TIME, \"\", \"%f\"\n" +"IFIELD TIMET_TIME, \"\", \"%ld\"\n" +; static char xmap[] = "# gpsbabel XCSV style file\n" "#\n" @@ -519,4 +567,4 @@ static char xmapwpt[] = "IFIELD DESCRIPTION, \"\", \"%-.78s\"\n" ; #include "defs.h" -style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "s_and_t", s_and_t } , { "ozi", ozi } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } , {0,0}}; +style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "tabsep", tabsep } , { "s_and_t", s_and_t } , { "ozi", ozi } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } , {0,0}}; diff --git a/gpsbabel/style/README.style b/gpsbabel/style/README.style index 4a3221cb3..740f124d2 100644 --- a/gpsbabel/style/README.style +++ b/gpsbabel/style/README.style @@ -256,6 +256,10 @@ The fields used by the XCSV parser are as follows: o LON_DECIMALDIR / LON_DIRDECIMAL Same as LAT_DECIMALDIR / LAT_DIRDECIMAL except LON_ defines LONGITUDE. + o LAT_DIR / LON_DIR + LAT_DIR returns the single character 'N' or 'S' depending on the + hemisphere of the latitude. LON_DIR returns 'E' or 'W' depending on + the hemisphere of the longitude. o ALT_FEET ALT_FEET is the position's ALTITUDE in FEET. This value is treated as diff --git a/gpsbabel/style/tabsep.style b/gpsbabel/style/tabsep.style new file mode 100644 index 000000000..0572dec8f --- /dev/null +++ b/gpsbabel/style/tabsep.style @@ -0,0 +1,46 @@ +# gpsbabel XCSV style file +# +# Format: Dumps all fields in a traditional Unix tab separated style +# +# The order of the fields (with the exception of LAT_DIR/LON_DIR) was +# the same as documented in README.style when this format was created. +# LAT_DIR/LON_DIR were undocumented, so I stuck them at the end of the +# other lat/lon fields. +# +# However, please add any new gpsbabel fields to the end (to avoid +# upsetting existing applications) regardless of where they land in +# the README.style documentation. +# + +DESCRIPTION All database fields on one tab-separated line + +# FILE LAYOUT DEFINITIIONS: +# +FIELD_DELIMITER TAB +RECORD_DELIMITER NEWLINE +BADCHARS TAB + +# +# INDIVIDUAL DATA FIELDS: +# +IFIELD INDEX, "", "%d" +IFIELD SHORTNAME, "", "%s" +IFIELD DESCRIPTION, "", "%s" +IFIELD NOTES, "", "%s" +IFIELD URL, "", "%s" +IFIELD URL_LINK_TEXT, "", "%s" +IFIELD ICON_DESCR, "", "%s" +IFIELD LAT_DECIMAL, "", "%f" +IFIELD LON_DECIMAL, "", "%f" +IFIELD LAT_INT32DEG, "", "%ld" +IFIELD LON_INT32DEG, "", "%ld" +IFIELD LAT_DECIMALDIR, "", "%f/%c" +IFIELD LON_DECIMALDIR, "", "%f/%c" +IFIELD LAT_DIRDECIMAL, "", "%c/%f" +IFIELD LON_DIRDECIMAL, "", "%c/%f" +IFIELD LAT_DIR, "", "%c" +IFIELD LON_DIR, "", "%c" +IFIELD ALT_FEET, "", "%fF" +IFIELD ALT_METERS, "", "%fM" +IFIELD EXCEL_TIME, "", "%f" +IFIELD TIMET_TIME, "", "%ld" -- 2.30.2